#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_energy_triplet2.info <<'%EOF%'
   cc_energy_triplet2
   ------------------
   Molecule:         H2O in C2v
   Wave Function:    CCS, CC2, CCSD / 6-31G
   Test Purpose:     Triplet excitation energies
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_energy_triplet2.mol <<'%EOF%'
BASIS
6-31G 
Water calc.
Triplet tests
    3      
        8.    1   
O     0.0        -0.12585272  0.0 
        1.    1
H    -1.42717891  0.99868674  0.0
        1.    1
H     1.42717891  0.99868674  0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_energy_triplet2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**WAVE FUNCTIONS
.TITLE
  Triplet excitation energies
.CC
*SCF INPUT 
.DOUBLY OCCUPIED
 3 1 1 0 
*CC INPUT 
.CCS
.CC2
.CCSD
.THRENR
 1.0d-10
.PRINT
  0
*CCEXCI
.NCCEXCI
 1 1 1 1 
 5 5 5 5
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################
#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_energy_triplet2.check
cat >>cc_energy_triplet2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-75.98351120" | wc -l`
CRIT2=`$GREP "Total MP2 * energy: * \-76.11276975" $log | wc -l`
CRIT3=`$GREP "Total CC2 * energy: * \-76.1135659" $log | wc -l`
CRIT4=`$GREP "Total CCSD * energy: * \-76.11931320" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=7
ERROR[1]="ENERGIES NOT CORRECT"


# CCS excitation energies:
CRIT1=`$GREP "\^1A1  \|    1   \|     ( |0)\.436338.  \|      11\.8733.  \|     95765\....  \| 100\.00" $log | wc -l`
CRIT2=`$GREP "\^3A1  \|    2   \|     ( |0)\.566111.  \|      15\.4046.  \|    124247\....  \| 100\.00" $log | wc -l`
CRIT3=`$GREP "\^3A1  \|    4   \|     1\.109257.  \|      30\.1844.  \|    243453\....  \| 100\.00" $log | wc -l`
CRIT4=`$GREP "\^1B2  \|    1   \|     ( |0)\.512261.  \|      13\.9393.  \|    112428\....  \| 100\.00" $log | wc -l`
CRIT5=`$GREP "\^3B2  \|    4   \|     1\.212183.  \|      32\.985..  \|    266043\....  \| 100\.00" $log | wc -l`
CRIT6=`$GREP "\^3B1  \|    2   \|     1\.080378.  \|      29\.398..  \|    237115\....  \| 100\.00" $log | wc -l`
CRIT7=`$GREP "\^1A2  \|    1   \|     ( |0)\.415252.  \|      11\.2996.  \|     91137\....  \| 100\.00" $log | wc -l`
CRIT8=`$GREP "\^3A2  \|    2   \|     1\.114383.  \|      30\.3239.  \|    244578\....  \| 100\.00" $log | wc -l`
CRIT9=`$GREP "\^3A2  \|    4   \|     1\.341322.  \|      36\.4992.  \|    294386\....  \| 100\.00" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[2]=9
ERROR[2]="CCS EXCITATION ENERGIES NOT CORRECT"


# CC2 excitation energies:
CRIT1=`$GREP "\^3A1  \|    1   \|     ( |0)\.360244.  \|       9\.8027.  \|     79064\....  \|  " $log | wc -l`
CRIT2=`$GREP "\^3A1  \|    4   \|     1\.107697.  \|      30\.14...  \|    243111\....  \|  " $log | wc -l`
CRIT3=`$GREP "\^3B2  \|    3   \|     1\.112085.  \|      30\.261..  \|    244074\....  \|  " $log | wc -l`
CRIT4=`$GREP "\^3B1  \|    1   \|     ( |0)\.277850.  \|       7\.5607.  \|     60981\....  \|  " $log | wc -l`
CRIT5=`$GREP "\^3B1  \|    4   \|     1\.222081.  \|      33\.2545.  \|    268215\....  \|  " $log | wc -l`
CRIT6=`$GREP "\^1A2  \|    1   \|     ( |0)\.390613.  \|      10\.6291.  \|     85729\....  \|  " $log | wc -l`
CRIT7=`$GREP "\^3A2  \|    2   \|     1\.057224.  \|      28\.7685.  \|    232033\....  \|  " $log | wc -l`
CRIT8=`$GREP "\^3A2  \|    3   \|     1\.280453.  \|      34\.8429.  \|    281026\....  \|  " $log | wc -l`
CRIT9=`$GREP "\^3A2  \|    4   \|     1\.388741.  \|      37\.789..  \|    304793\....  \|  " $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[3]=9
ERROR[3]="CC2 EXCITATION ENERGIES NOT CORRECT"


# CCSD excitation energies:
CRIT1=`$GREP "\^3A1  \|    1   \|     ( |0)\.362893.  \|       9\.8748.  \|     79645\.9..  \|  " $log | wc -l`
CRIT2=`$GREP "\^3A1  \|    3   \|     ( |0)\.989388.  \|      26\.9226.  \|    217145\....  \|  " $log | wc -l`
CRIT3=`$GREP "\^3A1  \|    5   \|     1\.13426(7|8).  \|      30\.8650.  \|    24894[23]\....  \|  " $log | wc -l`
CRIT4=`$GREP "\^1B2  \|    1   \|     ( |0)\.49160[67].  \|      13\.377[23].  \|    107895\....  \|  " $log | wc -l`
CRIT5=`$GREP "\^3B2  \|    3   \|     ( |0)\.966323.  \|      26\.29...  \|    212083\....  \|  " $log | wc -l`
CRIT6=`$GREP "\^3B2  \|    4   \|     1\.045679.  \|      28\.4543.  \|    229500\....  \|  " $log | wc -l`
CRIT7=`$GREP "\^3A2  \|    1   \|     ( |0)\.371942.  \|      10\.1210.  \|     8163.\....  \|  " $log | wc -l`
CRIT8=`$GREP "\^3A2  \|    2   \|     ( |0)\.967994.  \|      26\.3404.  \|    212450\....  \|  " $log | wc -l`
CRIT9=`$GREP "\^3A2  \|    3   \|     ( |0)\.991852.  \|      26\.989..  \|    217686\....  \|  " $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[4]=9
ERROR[4]="CCSD EXCITATION ENERGIES NOT CORRECT"


PASSED=1
for i in 1 2 3 4
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
